/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generadorcommun;

import java.sql.*;

/**
 *
 * @author Martin
 */
public class DataBase {
    private static  DataBase instance;

    private Connection conexion;
    private  DataBase() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }

    public static DataBase getInstance() {
        if (instance == null){
            instance = new DataBase();
        }
        return instance;
    }


    public void crearConexion () throws SQLException{
        this.conexion = DriverManager.getConnection ("jdbc:mysql://localhost:3306/dbjava","root", "root");
    }

    public void cerrarConexion() throws SQLException{
        this.conexion.close();
    }

    public void ejecutarCreateInsertUpDateDelete(String query) throws SQLException{
        crearConexion();
        Statement st = this.conexion.createStatement();
        st.executeUpdate(query);
        st.close();
        cerrarConexion();
    }

}
